﻿Imports System.Collections.Generic
Imports System.Data
Imports System.Windows.Forms
Imports Microsoft.Reporting.WebForms
Partial Class Form_frmRptAmlo
    Inherits System.Web.UI.Page

    Dim strSql As String

    Dim strRptType As String
    Dim strBranchCode As String
    Dim strDeptCode As String
    Dim strRptNo As String
    Dim strTypeDate As String
    Dim strStartDate As String
    Dim strEndDate As String
    Dim strSignType As String
    Dim strSaveType As String
    Dim UserRight As clsSessionMenuRight

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.AddHeader("Cache-control", "no-store, must-revalidate, private,no-cache")
        Response.AddHeader("Pragma", "no-cache")
        Dim dsAmlo As DataSet = Nothing
        Dim cls As New clsDatabase
        Dim clsFormatDate As New clsDateFormat
        Dim aDate As Date
        Dim bDate As Date

        strRptType = Request.Item("RPTTYPE")
        strBranchCode = Request.Item("BRANCHCODE")
        strDeptCode = Request.Item("DEPTCODE")
        strRptNo = Request.Item("RPTNO")
        strTypeDate = Request.Item("TYPEDATE")
        strStartDate = Request.Item("STARTDATE")
        strEndDate = Request.Item("ENDDATE")
        strSignType = Request.Item("SIGNTYPE")
        strSaveType = Request.Item("ISSEND")

        strSql = ""

        UserRight = Session("clsMenuRight")


        


        If Not (IsPostBack) Then
            If (strRptType = "M51") Then
                reportAMLO101()
            ElseIf (strRptType = "M52") Then
                reportAMLO102()
            ElseIf (strRptType = "M53") Then
                reportAMLO103()
            End If

            If Not (strSql = "") Then
                With sqlDtsAmlo
                    .SelectCommand = strSql

                    'If Not (strYear = "") Then
                    '    .SelectParameters.Add(":" + "RPTYEAR", strYear)
                    'End If

                    If Not (strRptNo = "") Then
                        .SelectParameters.Add(":" + "RPTNO", strRptNo)
                    End If

                    If Not (strStartDate = "" And strEndDate = "") Then
                        aDate = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, strDateIsChk:=strStartDate)
                        bDate = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, strDateIsChk:=strEndDate)

                        .SelectParameters.Add(":" + "STARTDATE", System.Data.DbType.DateTime, aDate.ToString("yyyy/MM/dd"))
                        .SelectParameters.Add(":" + "ENDDATE", System.Data.DbType.DateTime, bDate.ToString("yyyy/MM/dd"))

                    End If
                    If Not (strSignType = "") Then
                        .SelectParameters.Add(":" + "SIGNTYPE", strSignType)
                    End If
                    If Not (strSaveType = "") Then
                        .SelectParameters.Add(":" + "SAVETYPE", strSaveType)
                    End If

                    If Not (strDeptCode = "0") Then
                        .SelectParameters.Add(":" + "DEPTCODE", strDeptCode)
                    End If
                    If Not (strBranchCode = "0") Then
                        .SelectParameters.Add(":" + "BRANCHCODE", strBranchCode)
                    End If

                    If (UserRight.getRoleGroup > 69) Then

                    ElseIf (UserRight.getRoleGroup > 59) Then 'Admin เขต 
                        .SelectParameters.Add(":" + "ZONECODE", UserRight.getZoneCode)
                    ElseIf (UserRight.getRoleGroup > 49) Then 'Admin สาขา
                        .SelectParameters.Add(":" + "ZONECODE", UserRight.getZoneCode)
                    ElseIf (UserRight.getRoleGroup < 50) Then 'user ทั่วไป
                        .SelectParameters.Add(":" + "ZONECODE", UserRight.getZoneCode)
                        .SelectParameters.Add(":" + "CREATEBY", UserRight.getUserName)
                    End If






                End With
                Dim params As New List(Of ReportParameter)
                params.Add(New ReportParameter("prmStartDate", strStartDate))
                params.Add(New ReportParameter("prmEndDate", strEndDate))
                ReportViewer1.LocalReport.SetParameters(params)
                '  ReportViewer1.RefreshReport()



            End If
        End If




    End Sub

    Private Sub reportAMLO101()
        Me.ReportViewer1.LocalReport.ReportPath = "Form\reportAmlo\rptAmlo101.rdlc"
        Dim a As New Microsoft.Reporting.WebForms.ReportDataSource
        a.DataSourceId = "sqlDtsAmlo"
        a.Name = "dtsAmlo101"

        Me.ReportViewer1.LocalReport.DataSources.Add(a)
        strSql = "SELECT     AMLO101.RPTSEQ,        AMLO101.RPTTYPE,          AMLO101.RPTYEAR, " _
                      & "      AMLO101.RPTNO,         AMLO101.RPTREV,           AMLO101.BRANCHCODE, " _
                      & "      AMLO101.DEPTCODE,      AMLO101.RPTDATE,          AMLO101.TRANSDATE, " _
                      & "      AMLO101.TRANSTYPE,     AMLO101.TRANSTYPEOTHER,   mtsctype1.TYPE_TSC_NAME TSCNAME, " _
                      & "      AMLO101.OBJBIZ, SBRANCH.BRANCHNAME ,SDEPARTMENT.DEPTNAME ," _
                      & "      AMLO101.OBJBIZOTHER,   AMLO101.SAVETYPE,         AMLO101.SAVEDATE, " _
                      & "      AMLO101.SIGNTYPE,      AMLO101.ISSEND,           AMLO101.SENDDATE, " _
                      & "      AMLO101.CREATEBY,      AMLO101.CREATEDATE,       AMLO101.UPDATEBY, " _
                      & "      AMLO101.UPDATEDATE,    AMLO101.ISSENDCONFIRM,    AMLODETAIL101.PREFIX, " _
                      & "      AMLODETAIL101.FIRSTNAME, AMLODETAIL101.MIDNAME,  AMLODETAIL101.LASTNAME, " _
                      & " AMLO101.ACCOUNTNO, AMLO101.TRANSAMT, AMLO101.CURRENCY " _
                      & " FROM         " & System.Configuration.ConfigurationSettings.AppSettings("TableAMLO101") & " " _
                      & "                     INNER JOIN " & System.Configuration.ConfigurationSettings.AppSettings("TableAMLODETAIL101") & " " _
                      & "                     ON AMLO101.RPTSEQ = AMLODETAIL101.RPTSEQ " _
                      & "                     left join " & System.Configuration.ConfigurationSettings.AppSettings("TableMTSCTYPE1") & " " _
                      & "                     on mtsctype1.TYPE_TSC_ID =amlo101.TRANSTYPE " _
                      & "                     left join  " & System.Configuration.ConfigurationSettings.AppSettings("TableSDEPARTMENT") & " on amlo101.DEPTCODE =  SDEPARTMENT.DEPTCODE " _
                      & "                     left join  " & System.Configuration.ConfigurationSettings.AppSettings("TableSBRANCH") & " on amlo101.BRANCHCODE = SBRANCH.BRANCHCODE  " _
                      & "    where AMLODETAIL101.RPTIDX =1 and AMLO101.iscomplete=1"

        'If Not (strYear = "") Then
        '    strSql = strSql + " and " + "ADMIN.AMLO101.RPTYEAR =:RPTYEAR"
        'End If

        If Not (strRptNo = "") Then
            strSql = strSql + " and " + "AMLO101.RPTNO=:RPTNO"
        End If

        If Not (strStartDate = "" And strEndDate = "") Then
            If (strTypeDate = "1") Then
                strSql = strSql + " and " + "AMLO101.TRANSDATE >= :STARTDATE and AMLO101.TRANSDATE <= :ENDDATE "
            ElseIf (strTypeDate = "2") Then
                strSql = strSql + " and " + "AMLO101.SAVEDATE >= :STARTDATE and AMLO101.SAVEDATE <= :ENDDATE "
            End If

        End If
        If Not (strSignType = "") Then
            strSql = strSql + " and " + "AMLO101.SIGNTYPE=:SIGNTYPE"
        End If
        If Not (strSaveType = "") Then
            strSql = strSql + " and " + "AMLO101.SAVETYPE=:SAVETYPE"
        End If

        If Not (strDeptCode = "0") Then
            strSql = strSql + " and " + "AMLO101.DEPTCODE=:DEPTCODE"
        End If
        If Not (strBranchCode = "0") Then
            strSql = strSql + " and " + "AMLO101.BRANCHCODE=:BRANCHCODE"
        End If

        If (UserRight.getRoleGroup > 69) Then

        ElseIf (UserRight.getRoleGroup > 59) Then 'Admin เขต 
            strSql = strSql + " and " + "AMLO101.ZONECODE=:ZONECODE"
        ElseIf (UserRight.getRoleGroup > 49) Then 'Admin สาขา
            strSql = strSql + " and " + "AMLO101.ZONECODE=:ZONECODE"
        ElseIf (UserRight.getRoleGroup < 50) Then 'user ทั่วไป
            strSql = strSql + " and " + "AMLO101.ZONECODE=:ZONECODE"
            strSql = strSql + " and " + "AMLO101.CREATEBY=:CREATEBY"

        End If

    End Sub

    Private Sub reportAMLO102()
        Me.ReportViewer1.LocalReport.ReportPath = "Form\reportAmlo\rptAmlo102.rdlc"
        Dim a As New Microsoft.Reporting.WebForms.ReportDataSource
        a.DataSourceId = "sqlDtsAmlo"
        a.Name = "dsAmlo102"

        Me.ReportViewer1.LocalReport.DataSources.Add(a)

        strSql = " SELECT     AMLO102.RPTSEQ,AMLO102.RPTTYPE,AMLO102.RPTYEAR,AMLO102.RPTNO,AMLO102.RPTREV, " _
                & "           AMLO102.BRANCHCODE,SBRANCH.BRANCHNAME ,AMLO102.DEPTCODE,SDEPARTMENT.DEPTNAME , " _
                & "           AMLO102.RPTDATE,AMLO102.TRANSDATE,AMLO102.TRANSTYPE,mtsctype2.TSCTYPENAME TSCNAME, " _
                & "           AMLO102.ASSETTYPE,MASSETTYPE.ASSETTYPE ASSETTYPENAME,AMLO102.TRANSTYPEOTHER, " _
                & "           AMLO102.OBJBIZ,AMLO102.OBJBIZOTHER,AMLO102.SAVETYPE,AMLO102.SAVEDATE, " _
                & "           AMLO102.SIGNTYPE,AMLO102.ISSEND,AMLO102.SENDDATE, " _
                & "           AMLO102.CREATEBY,AMLO102.CREATEDATE,AMLO102.UPDATEBY,AMLO102.UPDATEDATE, " _
                & "           AMLO102.ISSENDCONFIRM,AMLODETAIL102.PREFIX,AMLODETAIL102.FIRSTNAME,AMLODETAIL102.MIDNAME, " _
                & "           AMLODETAIL102.LASTNAME,AMLO102.ACCOUNTNO, AMLO102.TRANSAMT, AMLO102.CURRENCY  " _
                & " FROM       " & System.Configuration.ConfigurationSettings.AppSettings("TableAMLO102") & " INNER JOIN " & System.Configuration.ConfigurationSettings.AppSettings("TableAMLODETAIL102") & "  " _
                & "                            ON AMLO102.RPTSEQ = AMLODETAIL102.RPTSEQ " _
                & "           left join " & System.Configuration.ConfigurationSettings.AppSettings("TableMTSCTYPE2") & " on amlo102.TRANSTYPE =  mtsctype2.TSCTYPEID " _
                & "           left join  " & System.Configuration.ConfigurationSettings.AppSettings("TableMASSETTYPE") & " on amlo102.ASSETTYPE =  MASSETTYPE.ASSETTYPEID " _
                & "           left join  " & System.Configuration.ConfigurationSettings.AppSettings("TableSDEPARTMENT") & " on amlo102.DEPTCODE =  SDEPARTMENT.DEPTCODE  " _
                & "           left join  " & System.Configuration.ConfigurationSettings.AppSettings("TableSBRANCH") & " on amlo102.BRANCHCODE = SBRANCH.BRANCHCODE  " _
                & " where AMLODETAIL102.RPTIDX =1 and AMLO102.iscomplete=1 "

        'If Not (strYear = "") Then
        '    strSql = strSql + " and " + "ADMIN.AMLO102.RPTYEAR =:RPTYEAR"
        'End If
        If Not (strRptNo = "") Then
            strSql = strSql + " and " + "AMLO102.RPTNO=:RPTNO"
        End If

        If Not (strStartDate = "" And strEndDate = "") Then
            If (strTypeDate = "1") Then
                strSql = strSql + " and " + "AMLO102.TRANSDATE >= :STARTDATE and AMLO102.TRANSDATE <= :ENDDATE "
            ElseIf (strTypeDate = "2") Then
                strSql = strSql + " and " + "AMLO102.SAVEDATE >= :STARTDATE and AMLO102.SAVEDATE <= :ENDDATE "
            End If

        End If
        If Not (strSignType = "") Then
            strSql = strSql + " and " + "AMLO102.SIGNTYPE=:SIGNTYPE"
        End If
        If Not (strSaveType = "") Then
            strSql = strSql + " and " + "AMLO102.SAVETYPE=:SAVETYPE"
        End If

        If Not (strDeptCode = "0") Then
            strSql = strSql + " and " + "AMLO102.DEPTCODE=:DEPTCODE"
        End If
        If Not (strBranchCode = "0") Then
            strSql = strSql + " and " + "AMLO102.BRANCHCODE=:BRANCHCODE"
        End If

        If (UserRight.getRoleGroup > 69) Then

        ElseIf (UserRight.getRoleGroup > 59) Then 'Admin เขต 
            strSql = strSql + " and " + "AMLO102.ZONECODE=:ZONECODE"
        ElseIf (UserRight.getRoleGroup > 49) Then 'Admin สาขา
            strSql = strSql + " and " + "AMLO102.ZONECODE=:ZONECODE"
        ElseIf (UserRight.getRoleGroup < 50) Then 'user ทั่วไป
            strSql = strSql + " and " + "AMLO102.ZONECODE=:ZONECODE"
            strSql = strSql + " and " + "AMLO102.CREATEBY=:CREATEBY"

        End If


    End Sub

    Private Sub reportAMLO103()
        Me.ReportViewer1.LocalReport.ReportPath = "Form\reportAmlo\rptAmlo103.rdlc"
        Dim a As New Microsoft.Reporting.WebForms.ReportDataSource
        a.DataSourceId = "sqlDtsAmlo"
        a.Name = "dsAmlo103"

        Me.ReportViewer1.LocalReport.DataSources.Add(a)
        strSql = " SELECT     AMLO103.RPTSEQ,AMLO103.RPTTYPE,AMLO103.RPTYEAR,AMLO103.RPTNO, " _
                & "           AMLO103.RPTREV, AMLO103.BRANCHCODE, AMLO103.DEPTCODE, SBRANCH.BRANCHNAME , " _
                & "           SDEPARTMENT.DEPTNAME ,AMLO103.RPTDATE,AMLO103.TRANSDATE, AMLO103.TRANSTYPE, " _
                & "           AMLO103.TRANSTYPEOTHER, mtsctype3.TSCTYPENAME TSCNAME,AMLO103.OBJBIZ, " _
                & "           AMLO103.OBJBIZOTHER, AMLO103.SAVETYPE, AMLO103.SAVEDATE, AMLO103.SIGNTYPE, " _
                & "           AMLO103.ISSEND, AMLO103.SENDDATE, AMLO103.CREATEBY, AMLO103.CREATEDATE, " _
                & "           AMLO103.UPDATEBY, AMLO103.UPDATEDATE, AMLO103.ISSENDCONFIRM, AMLODETAIL103.PREFIX, " _
                & "           AMLODETAIL103.FIRSTNAME, AMLODETAIL103.MIDNAME, AMLODETAIL103.LASTNAME ,AMLO103.ACCOUNTNO, " _
                & "           AMLO103.TRANSAMT, AMLO103.CURRENCY ,AMLO103.DOCREF " _
                & " FROM       " & System.Configuration.ConfigurationSettings.AppSettings("TableAMLO103") & " INNER JOIN " _
                & "                        " & System.Configuration.ConfigurationSettings.AppSettings("TableAMLODETAIL103") & " ON AMLO103.RPTSEQ = AMLODETAIL103.RPTSEQ " _
                & "                        left join " _
                & "                       " & System.Configuration.ConfigurationSettings.AppSettings("TableMTSCTYPE3") & " on admin.mtsctype3.TSCTYPEID =admin.AMLO103.TRANSTYPE " _
                & "                        left join " _
                & "                        " & System.Configuration.ConfigurationSettings.AppSettings("TableSDEPARTMENT") & " on AMLO103.DEPTCODE =  SDEPARTMENT.DEPTCODE " _
                & "                        left join " _
                & "                        " & System.Configuration.ConfigurationSettings.AppSettings("TableSBRANCH") & " on AMLO103.BRANCHCODE = SBRANCH.BRANCHCODE " _
                & " where AMLODETAIL103.RPTIDX =1 and AMLO103.iscomplete=1 "

        'If Not (strYear = "") Then
        '    strSql = strSql + " and " + "ADMIN.AMLO103.RPTYEAR =:RPTYEAR"
        'End If
        If Not (strRptNo = "") Then
            strSql = strSql + " and " + "AMLO103.RPTNO=:RPTNO"
        End If

        If Not (strStartDate = "" And strEndDate = "") Then
            If (strTypeDate = "1") Then
                strSql = strSql + " and " + "AMLO103.TRANSDATE >= :STARTDATE and AMLO103.TRANSDATE <= :ENDDATE "
            ElseIf (strTypeDate = "2") Then
                strSql = strSql + " and " + "AMLO103.SAVEDATE >= :STARTDATE and AMLO103.SAVEDATE <= :ENDDATE "
            End If

        End If
        If Not (strSignType = "") Then
            strSql = strSql + " and " + "AMLO103.SIGNTYPE=:SIGNTYPE"
        End If
        If Not (strSaveType = "") Then
            strSql = strSql + " and " + "AMLO103.SAVETYPE=:SAVETYPE"
        End If

        If Not (strDeptCode = "0") Then
            strSql = strSql + " and " + "AMLO103.DEPTCODE=:DEPTCODE"
        End If
        If Not (strBranchCode = "0") Then
            strSql = strSql + " and " + "AMLO103.BRANCHCODE=:BRANCHCODE"
        End If

        If (UserRight.getRoleGroup > 69) Then

        ElseIf (UserRight.getRoleGroup > 59) Then 'Admin เขต 
            strSql = strSql + " and " + "AMLO103.ZONECODE=:ZONECODE"
        ElseIf (UserRight.getRoleGroup > 49) Then 'Admin สาขา
            strSql = strSql + " and " + "AMLO103.ZONECODE=:ZONECODE"
        ElseIf (UserRight.getRoleGroup < 50) Then 'user ทั่วไป
            strSql = strSql + " and " + "AMLO103.ZONECODE=:ZONECODE"
            strSql = strSql + " and " + "AMLO103.CREATEBY=:CREATEBY"

        End If
    End Sub

    


End Class
